package com.bootcamp.java;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @program: ArrayCode
 * @description: create a double list and calculate it.
 * @author: Keyu Li
 * @create: 2021-08-26 20:41
 **/

public class DoubleArrayCalculate {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("how many double numbers? : ");
        int leng = Integer.parseInt(sc.nextLine());
        double[] arr = new double[leng];
        for (int i = 0; i < leng; i++) {
            System.out.print("please input the " + (i + 1) + "/" + leng + " double: ");
            arr[i] = Double.parseDouble(sc.nextLine());
        }

        if (arr[0] == 0.0) {
            System.out.println("Error: first element cannot be 0!");
            return;
        }
        System.out.println("origin array: " + Arrays.toString(arr));
        for (int i = 1; i < arr.length; i++) {
            arr[i] = (int) (100 * arr[i] / arr[0]) / 100.0;
        }
        arr[0] = 1;
        System.out.println("final array: " + Arrays.toString(arr));
    }
}
